import axios from 'axios'
import Vue from 'vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

export function request(config){
	//1.创建axios实例
	const instance = axios.create({
		baseURL:'https://www.liulongbin.top:8888/api/private/v1/',
		timeout:5000
	})
	//2.axios拦截器
//	axios.interceptors 全局拦截
  //拦截请求
	instance.interceptors.request.use(config=>{
	  NProgress.start()
		//拦截放行
    config.headers.authorization = window.sessionStorage.getItem('token')
		return config
	},err=>{

	})
  //拦截响应
  instance.interceptors.response.use(res=>{
    NProgress.done()
    return res.data
  },error => {

  })

  //3.发送真正的网络请求，返回的是promise对象
  return instance(config)
}


